package com.lvmama.controller.rhino.topic;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.lvmama.client.rhino.TopicClient;
import com.lvmama.common.result.Result;
import com.lvmama.pojo.dto.rhino.topic.SpecialTopicDTO;
import com.lvmama.pojo.entity.rhino.topic.OrderCondition;
import com.lvmama.pojo.entity.rhino.topic.PitPV;
import com.lvmama.pojo.entity.rhino.topic.SpecialTopicFunnelData;
import com.lvmama.pojo.entity.rhino.topic.TopicFunnelDataQuery;

@Controller
@RequestMapping("/topic")
public class TopicController {

    /**
     *
     */
    @Autowired
    TopicClient topicClient;


    @RequestMapping(value = "/topicTree",method = RequestMethod.GET)
    public String topicTree(ModelMap model) {
        return "specialTopic/topicTree";
    }


    @RequestMapping(value = "/topicAjaxData",method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public Result<Map<String, Object>> getThemeTab(SpecialTopicDTO specialTopicDTO) {

        return topicClient.topicAjaxData(specialTopicDTO);

    }

    @RequestMapping(value = "/topicClickAll",method = {RequestMethod.GET,RequestMethod.POST})
    public String getTopicClickAll(ModelMap model, SpecialTopicDTO specialTopicDTO,int pageCurrentNum, HttpServletResponse response) {
        OrderCondition orderCondition = new OrderCondition();
        if(pageCurrentNum >1){
            orderCondition.setCurrentPage(pageCurrentNum);
        }
        specialTopicDTO.setOrderCondition(orderCondition);
        Map<String, PageInfo<PitPV>> clickAll = topicClient.getTopicClickAll(specialTopicDTO).getData();
        PageInfo<PitPV> page= clickAll.get("page");

        model.addAttribute("page", page);
        model.addAttribute("topicPVList", page.getList());
        model.addAttribute("chooseTime", specialTopicDTO.getChooseTime());
        model.addAttribute("code", specialTopicDTO.getCode());
        model.addAttribute("platform", specialTopicDTO.getPlatform());
        response.setHeader("X-Frame-Options", "SAMEORIGIN");

        return "specialTopic/topicClickDetail";

    }


    @RequestMapping(value = "/topicClickData",method = RequestMethod.GET)
    @ResponseBody
    public Result<Map<String, Object>> getTopicClickData(SpecialTopicDTO specialTopicDTO) {
        return topicClient.getTopicClickData(specialTopicDTO);
    }


    @RequestMapping(value = "/chartData",method = RequestMethod.GET)
    @ResponseBody
    public Result<Map<String, Object>> chartData(SpecialTopicDTO specialTopicDTO) {
        return topicClient.chartData(specialTopicDTO);
    }


    @RequestMapping(value = "/getPageChartData",method = RequestMethod.GET)
    @ResponseBody
    public Result<Map<String, Object>> getPageChartData(SpecialTopicDTO specialTopicDTO) {
        return topicClient.getPageChartData(specialTopicDTO);
    }

    /**
     * 查询专题漏斗数据
     *
     * @param query
     * @return
     */
    @RequestMapping(value = "/getTopicFunnel",method = RequestMethod.GET)
    @ResponseBody
    public Result<List<SpecialTopicFunnelData>> getTopicFunnel( TopicFunnelDataQuery query) {
        return topicClient.getTopicFunnel(query);
    }


}
